package cn.wangdian.erp.demo;

import cn.wangdian.erp.sdk.Client;
import cn.wangdian.erp.sdk.Pager;
import cn.wangdian.erp.sdk.WdtErpException;
import cn.wangdian.erp.sdk.api.purchase.PurchaseProviderGoodsAPI;
import cn.wangdian.erp.sdk.api.purchase.dto.PurchaseProviderGoodsSearchRequest;
import cn.wangdian.erp.sdk.api.purchase.dto.PurchaseProviderGoodsSearchResponse;
import cn.wangdian.erp.sdk.impl.ApiFactory;
import cn.wangdian.erp.sdk.impl.DefaultClient;

public class PurchaseProvider
{
	public static void main(String[] args) throws WdtErpException
	{
		Client client = DefaultClient.get("wdterp30", "http://172.172.1.62:30000/", "xyx_api",
				"e8866c1681dacc9488a19c89991791b8:8f5800dab84b7a8d614e92cba739032c");
		PurchaseProviderGoodsAPI api = ApiFactory.get(client, PurchaseProviderGoodsAPI.class);

		queryWithDetailTest(api);
	}

	private static void queryWithDetailTest(PurchaseProviderGoodsAPI api) throws WdtErpException
	{
		int pageSize = 2;
		Pager pager = new Pager(pageSize, 0, true);

		PurchaseProviderGoodsSearchRequest request = new PurchaseProviderGoodsSearchRequest();
		request.setSpecNo("gy01");

		PurchaseProviderGoodsSearchResponse response = api.queryWithDetail(request, pager);
		Integer total = response.getTotal();
		if (total == null || pageSize >= total)
		{
			System.out.println("处理数据");
			return;
		}

		int totalPage = (total % pageSize == 0 ? total / pageSize : total / pageSize + 1) - 1;
		pager.setCalcTotal(false);
		for (int i = totalPage; i >= 0; --i)
		{
			pager.setPageNo(i);
			System.out.print("pager: page_size:"+pageSize+" page_no:"+i+" ");
			response = api.queryWithDetail(request, pager);
			System.out.println("处理数据");
		}
	}
}
